<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'north',title:'过滤条件',collapsible:true" style="height:120px">
        <p>
            <span>
                标题 :
            </span>
            <input id="article-add-title" class="easyui-textbox" type="text" name="title" />
            <input id="article-add-id" style="display:none"/>
        </p>
        <a id="article-add-submit" href="javascript:void(0)" class="easyui-linkbutton" data-options="text:'提交'">
        </a>
    </div>
    <div data-options="region:'center',border:false,fit:true">
        <div id="article-add-content" style="height:600px">
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function()
    {
        var id = $('#center-tab').tabs('getSelected').panel('options').id;
        var editor = new wangEditor('article-add-content');
        editor.config.uploadImgUrl = ctx + '/imgs/wangEditor';
        editor.create();
        if (id == null) 
        {
            $('#article-add-submit').click(function()
            {
                $.ajax(
                {
                    url: ctx + '/article',
                    type: 'post',
                    data: 
                    {
                        markdown: false,
                        text_content: editor.$txt.html(),
                        html_content: editor.$txt.html(),
                        title: $('#article-add-title').textbox('getText')
                    },
                    success: function(result)
                    {
                        if (result.success) 
                        {
                            $.messager.alert('消息', '文章已经保存成功', 'info', function()
                            {
                                closeNowTab();
                            });
                        }
                        else 
                        {
                            $.messager.alert('警告', '保存异常', 'error');
                        }
                    }
                });
            });
        }
        else 
        {
            $.ajax(
            {
                url: ctx + "/article/" + id,
                type: 'get',
                dataType: 'json',
                success: function(result)
                {
                    if (result.success) 
                    {
                        $('#article-add-id').val(result.data.id);
                        $('#article-add-title').textbox('setValue', result.data.title);
                        editor.$txt.html(result.data.text_content);
                    }
                    else 
                    {
                        alert(result.data);
                    }
                }
            });
            $('#article-add-submit').click(function()
            {
                $.ajax(
                {
                    url: ctx + '/article/' + id,
                    type: 'put',
                    data: 
                    {
                        markdown: false,
                        text_content: editor.$txt.html(),
                        html_content: editor.$txt.html(),
                        title: $('#article-add-title').textbox('getText')
                    },
                    success: function(result)
                    {
                        if (result.success) 
                        {
                            $.messager.alert('消息', '文章已经保存成功', 'info', function()
                            {
                                closeNowTab();
                            });
                        }
                        else 
                        {
                            $.messager.alert('警告', '保存异常', 'error');
                        }
                    }
                });
            });
        }
        
    });
</script>
